package com.base.cn.platform.os.controller.count;

import com.base.cn.platform.os.common.utils.count.PageFrom;
import com.base.cn.platform.os.common.utils.count.PageKeyUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.manage.count.PageViewCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 统计pv uv
 */
@RestController
@RequestMapping("/api/pageCount")
public class PageDataController {
    @Autowired
    private PageViewCountService pageViewCountService;


    /**
     * 初始化讲师列表页面
     * @return String
     */
    @RequestMapping("/page")
    public Map<String,Object> page(@RequestParam("key") int key, @RequestParam("fromSource") int fromSource){

        StringBuilder  keyString = new StringBuilder();
        StringBuilder  fromString = new StringBuilder();
        switch (key){
               case 1:
                /**首页*/
                keyString.append(PageKeyUtils.INDEX);
                break;
            case 2:
                /**课程详细*/
                keyString.append(PageKeyUtils.COURSE_INFO);
                break;
            case 3:
                /**直播详情*/
                keyString.append(PageKeyUtils.COURSE_INFO);
                break;
            case 4:
                /**考试首页*/
                keyString.append(PageKeyUtils.EXAM_INDEX);
                break;
            case 5:
                /**班级首页*/
                keyString.append(PageKeyUtils.CLASS_INDEX);
                break;
            case 6:
                /**资讯首页*/
                keyString.append(PageKeyUtils.CMS_INDEX);
                break;
            case 7:
                /**免费直播*/
                keyString.append(PageKeyUtils.OPEN_INDEX);
                break;
            case 8:
                /**当首页推荐的banner是专题时调用*/
                keyString.append(PageKeyUtils.ACTIVITY_INFO);
                break;
        }
        switch (fromSource){
            case 1:
                /**PC端*/
                fromString.append(PageFrom.PAGE_FROM_PC);
                break;
            case 2:
                /**手机站端*/
                fromString.append(PageFrom.PAGE_FROM_MOBILE);
                break;
            case 3:
                /**APP应用端 android*/
                fromString.append(PageFrom.PAGE_FROM_APP);
                break;
            case 4:
                /**小程序*/
                fromString.append(PageFrom.PAGE_FROM_APPLY);
                break;
            case 5:
                /**APP_IOS应用端*/
                fromString.append(PageFrom.PAGE_FROM_APP_IOS);
                break;
        }
       if(keyString.length()>0&&fromString.length()>0){
           pageViewCountService.addPageCount(keyString.toString(), fromString.toString());
           return ResultUtil.SUCCESS("保存成功");
        }
        if(keyString.length()<=0){
            return ResultUtil.SUCCESS("页面关键字错误");
        }
        if(fromString.length()<=0){
            return ResultUtil.SUCCESS("访问来源错误");
        }
        return ResultUtil.ERROR("系统错误");
    }
}
